#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QTime>

MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->btnGetText, &QPushButton::clicked, this, &MainWindow::onBtnGetTextClicked);
    connect(ui->btnSetText, &QPushButton::clicked, this, &MainWindow::onBtnSetTextClicked);
    connect(ui->btnAlignLeft, &QPushButton::clicked, this, &MainWindow::onBtnAlignLeftClicked);
    connect(ui->btnCenter, &QPushButton::clicked, this, &MainWindow::onBtnAlignCenterClicked);
    connect(ui->btnRight, &QPushButton::clicked, this, &MainWindow::onBtnAlignRightClicked);
    connect(ui->btnDisableWrap, &QPushButton::clicked, this, &MainWindow::onBtnDisableWrap);
    connect(ui->btnEnableWrap, &QPushButton::clicked, this, &MainWindow::onBtnEnableWrap);
    connect(ui->btnToggleImage, &QPushButton::clicked, this, &MainWindow::onBtnToggleImageClicked);
}

MainWindow::~MainWindow()
{
    delete ui;
}

/** 获取文本
 * @brief MainWindow::onBtnGetTextClicked
 */
void MainWindow::onBtnGetTextClicked()
{
    QMessageBox::information(this, "标签显示", ui->lbTime->text());
}

/** 设置文本
 * @brief MainWindow::onBtnSetTextClicked
 */
void MainWindow::onBtnSetTextClicked()
{
    ui->lbTime->setText(QTime::currentTime().toString());
}

/** 左对齐
 * @brief MainWindow::onBtnAlignLeftClicked
 */
void MainWindow::onBtnAlignLeftClicked()
{
    ui->lbAlign->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
}

/** 居中对齐
 * @brief MainWindow::onBtnAlignCenterClicked
 */
void MainWindow::onBtnAlignCenterClicked()
{
    ui->lbAlign->setAlignment(Qt::AlignCenter);
}

/** 右对齐
 * @brief MainWindow::onBtnAlignRightClicked
 */
void MainWindow::onBtnAlignRightClicked()
{
    ui->lbAlign->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
}

/** 禁止换行
 * @brief MainWindow::onBtnDisableWrap
 */
void MainWindow::onBtnDisableWrap()
{
    ui->lbWrap->setWordWrap(false);
}

/** 允许换行
 * @brief MainWindow::onBtnEnableWrap
 */
void MainWindow::onBtnEnableWrap()
{
    ui->lbWrap->setWordWrap(true);
}

/** 切换图片
 * @brief MainWindow::onBtnToggleImageClicked
 */
int index = 0;

void MainWindow::onBtnToggleImageClicked()
{
    QPixmap pixmap;

    if(index == 0) {
        pixmap.load(":/icon/orange.png");
        index++;
    } else {
        pixmap.load(":/icon/watermelon.png");
        index = 0;
    }

    ui->lbImage->setPixmap(pixmap);

    ui->lbImage->setAlignment(Qt::AlignCenter);
}
